Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spree::OptionValue#name delegates to Spree::OptionType even when nil #3517

Conversation

SamuelMartini
Copy link
Contributor

@SamuelMartini SamuelMartini commented Feb 14, 2020

Description
Spree::OptionValue#name is delegated to Spree::OptionType with option_type prefix (option_type_name).

The json response of Spree::Api::OptionValuesController uses the *option_value_attributes helper variable which includes :option_type_name.
If for some reason an option value is created without option_type the above controller will return a 500 error because of the name delegation.

For instance, Spree::Api::OptionValuesController#create allows to create an option value record with only name and presentation params. Once created, the json response view will call *option_value_attributes with option_type_name breaking the app.

This pr also:

  • remove check_option_values from the option_values_controller_spec.rb
    because is not used anywhere in the file.
  • remove option value resource duplicated route.

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have added tests to cover this change (if needed)

…ame to it

Spree::OptionValue#name is delegated to Spree::OptionType with option_type
prefix (option_type_name).

https://github.com/solidusio/solidus/blob/v2.9.5/core/app/models/spree/option_value.rb#L17

The json response of Spree::Api::OptionValuesController uses the
*option_value_attributes helper variable which has :option_type_name.
If for some reason an option value is created without option_type the above
controller will return a 500 error because the name delegation.

This commit also remove check_option_values from the option_values_controller_spec.rb
because is not used anywhere in the file.
The above line already configures all the routes for the option value resource.
Copy link
Member

@spaghetticode spaghetticode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SamuelMartini thanks for catching this!

I am in favor of this change, I just wonder if we should allow creating option values without option type 🤔

Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SamuelMartini thanks. I'm ok with the change and I also can't see a scenario where someone could need an option value without an option type but this is reflected in model validations and it seems to be legit.

@kennyadsl kennyadsl changed the title Samuel martini/allow nil option value method delegation Spree::OptionValue#name delegates to Spree::OptionType even when nil Feb 18, 2020
@kennyadsl kennyadsl merged commit 72e7157 into solidusio:master Feb 18, 2020
@kennyadsl kennyadsl deleted the SamuelMartini/allow_nil_option_value_method_delegation branch February 18, 2020 09:41
waiting-for-dev added a commit to nebulab/solidus that referenced this pull request May 26, 2022
It makes no sense to have dangling option_values without an associated
option_type.

Ref solidusio#3309 & solidusio#3517
@kennyadsl
Copy link
Member

@SamuelMartini I know this is quite old, but any chance you remember why you needed to create an option value without an option type?

cpfergus1 pushed a commit to cpfergus1/solidus that referenced this pull request Aug 25, 2022
It makes no sense to have dangling option_values without an associated
option_type.

Ref solidusio#3309 & solidusio#3517
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants